package com.ymatou.iapi.marketingmanage.service;

import java.util.TreeMap;

import com.google.gson.JsonObject;
import com.google.gson.reflect.TypeToken;
import com.ymatou.iapi.marketingmanage.parameter.PromotionPolicy;
import com.ymt.base.YmatouBaseCall;
import com.ymt.core.tool.FormatUtil;
import com.ymttest.utils.EnvSetup;

/**
 * 促销活动详情Call FreeMaker Template自动生成代码
 */
public class GetPromotionByIdCall extends YmatouBaseCall {
	private static String opurl = "api/Promotion/GetPromotionById";

	public GetPromotionByIdCall() {
		super(EnvSetup.getSystemUrl("marketingmanage_iapi"), opurl, "GET", "PARAM");
	}
	public GetPromotionByIdCall(String geturl) {
		super(EnvSetup.getSystemUrl(geturl), opurl, "GET", "PARAM");
	}
	@Override
	public void addDefHeader() {
		client.addHeader("Accept", "text/xml,text/javascript,text/html,application/json");
		client.addHeader("Content-Type", "application/json; charset=UTF-8");
	}

	public PromotionPolicy getPromotionPolicy() {
		PromotionPolicy recp = null;
		try {
			JsonObject json = getJsonObject().getAsJsonObject("Data");
			JsonObject recjson = json.get("PromotionInfo").getAsJsonObject();
			recp = (PromotionPolicy) FormatUtil.GSONToObject(recjson.toString(), PromotionPolicy.class);
		} catch (Throwable e) {
			return null;
		}
		return recp;
	}
	public TreeMap<String, Object> getTPromotionPolicy() {
		TreeMap<String, Object> recp = null;
		try {
			JsonObject json = getJsonObject().getAsJsonObject("Data");
			JsonObject recjson = json.get("PromotionInfo").getAsJsonObject();
			recp = (TreeMap<String, Object>) FormatUtil.GSONToObject(recjson.toString(),new TypeToken<TreeMap<String, Object>>() {}.getType());
		} catch (Throwable e) {
			return null;
		}
		return recp;
	}
}